" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below.  If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed.  It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
	syntax on
endif

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark


" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd		" Show (partial) command in status line.
"set showmatch		" Show matching brackets.
"set ignorecase		" Do case insensitive matching
"set smartcase		" Do smart case matching
"set incsearch		" Incremental search
"set autowrite		" Automatically save before commands like :next and :make
"set hidden             " Hide buffers when they are abandoned
"set mouse=a		" Enable mouse usage (all modes)

"""""""""""""""""""""""""""""General setting"""""""""""""""""""""""""""
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
	source /etc/vim/vimrc.local
endif


if filereadable("~/.vim/.vimJohnny")
	source /home/johnny/.vim/.vimJohnny
endif

if has("multi_byte")
	set encoding=utf-8
	set fileencoding=chinese
	set fileencodings=ucs-bom,utf-8,chinese
endif

set wrap
set hlsearch
filetype plugin on

colorscheme elflord
syntax on

set nocp
filetype plugin on
filetype indent on

set nu
set mouse=a

set foldenable
set foldmethod=syntax
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

let mapleader = ","
let g:winManagerWindowLayout='FileExplorer'

" Return to last edit position when opening files (You want this!)
 autocmd BufReadPost *
      \ if line("'\"") > 0 && line("'\"") <= line("$") |
     \   exe "normal! g`\"" |
     \ endif
" Remember info about open buffers on close
 set viminfo^=%


"""""""""""""""""""""""""""""Short Cuts""""""""""""""""""""""""""""""""""""
noremap 	<F2> :vsplit ~/.vimrc <CR>
		\:91 <CR> 
"noremap <leader><F2> :!cp ~/.vimrc $gglshellcmdpath/../../VIM/myInstall/vimrc -rf <CR>  
"                        \:!echo \"copy current .vimrc to my google VIM SVN\" <CR>

noremap <leader><F2> : call KeyF2()<CR>  
noremap 	<F3> :!find . -iname '*.c' -o -iname '*.cpp'  -o -iname '*.h' >cscope.files<CR>
			\:!cscope -b -i cscope.files -f cscope.out<CR>
			\: cs reset<CR>
			\:!ctags -L cscope.files<CR>
			\:set tags=./tags<CR>
noremap <leader><F3> :!./cscope.sh<CR>
			\:!cscope -b -i cscope.files -f cscope.out<CR>
			\:cs reset<CR>
			\:!ctags -L cscope.files<CR>
			\:set tags=./tags<CR>
noremap 	<F4> :TlistToggle<CR>
noremap <leader><F4> :TlistSync<CR>
noremap 	<F5> :call KeyF5()<CR>
noremap <leader><F5> :make clean;make<CR>
noremap		<F6> :call KeyF6()<CR> | "test comments

"vnoremap <c-]><F12>
"nnoremap <c-]><F12>
"map <leader>p ma"aYHmbgg"ap`bzt'a

 """"""""""""""""""""""""""""""
 " => Visual mode related
" When you press gv you vimgrep after the selected text
vnoremap <silent>  gv :call VisualSelection('gv')<CR>
" When you press <leader>r you can search and replace the selected text
vnoremap <silent><leader>r :call VisualSelection('replace')<CR>
 " " Visual mode pressing * or # searches for the current selection
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>

  " Useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
  " Opens a new tab with the current buffer's path
  " " Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/



   "NOTE shortcuts
   "H,M,L: 跳转屏幕顶部，中部，底部

""""""""""""""""""""""""""""""Tlist"""""""""""“”“"""""""""""""""""""""""""""
let Tlist_Ctags_Cmd="/usr/bin/ctags"
let Tlist_Use_LEFT_Window=1
let Tlist_File_Fold_Auto_Close=1
let Tlist_Show_One_File=1
let Tlist_GainFocus_On_ToggleOpen=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_Right_Window=1
let Tlist_File_Fold_Auto_Close=1

"""""""""""""""""""""""""""""Advanced Comment"""""""""""""""""""""""""""""""
vmap co :call EnhancedCommentify('','guess')<CR>
vmap cm :call EnhancedCommentify('','comment')<CR>
vmap dc :call EnhancedCommentify('','decomment')<CR>
map co :call EnhancedCommentify('','guess')<CR>
map cm :call EnhancedCommentify('','comment')<CR>
map dc :call EnhancedCommentify('','decomment')<CR>

"""""""""""""""""""""""""""""cscope"""""""""""""""""""""""""""""""""""""""""
if has("cscope")
	set csprg=/usr/bin/cscope
	set csto=0
	set cst
	set nocsverb
	" add any database in current directory

	if filereadable("cscope.out")
		cs add cscope.out
		" else add database pointed to by environment
	elseif $CSCOPE_DB != ""
		cs add $CSCOPE_DB
	endif
	set csverb
	set cscopetag
endif

""""""""""""""""""""""""""""Help Functions""""""""""""""""""""""""""""""""""

function! CmdLine(str)
	exe "menu Foo.Bar :" . a:str
	emenu Foo.Bar
	unmenu Foo
endfunction


function! VisualSelection(direction) range
	let l:saved_reg = @"
	execute "normal! vgvy"

	let l:pattern = escape(@", '\\/.*$^~[]')
	let l:pattern = substitute(l:pattern, "\n$", "", "")

	if a:direction == 'b'
		execute "normal ?" . l:pattern . "^M"
	elseif a:direction == 'gv'
		call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
	elseif a:direction == 'replace'
		call CmdLine("%s" . '/'. l:pattern . '/')
	elseif a:direction == 'f'
		execute "normal /" . l:pattern . "^M"
	endif

	let @/ = l:pattern
	let @" = l:saved_reg
endfunction

function! KeyF1()
	:make	
endfunction

function! KeyF2()
	:!sudo cp ~/.vimrc $gglshellcmdpath/../../VIM/myInstall/vimrc -rf  
	:!echo "copy current .vimrc to my google VIM SVN:$gglshellcmdpath/../../VIM/myInstall/vimrc" 
	
endfunction


function! KeyF3()
	:make	
endfunction


function! KeyF4()
	:make	
endfunction


function! KeyF5()
	:make	
endfunction

function! KeyF6()
	execute "q!"
endfunction
